package framework;

import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.List;

public class ZookeeprDemo {
    public static void main(String[] args) throws IOException, KeeperException, InterruptedException {
        ZooKeeper zooKeeper = new ZooKeeper("127.0.0.1:2181", 2000, null);
        List<String> children = zooKeeper.getChildren("/", false);
        System.out.println("children = " + children);
        String java = zooKeeper.create("/zookeeper/zoo", "hello zookeeper!".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        System.out.println("java = " + java);
        byte[] bytes = zooKeeper.getData("/zookeeper/zoo", false, null);
        String s = new String(bytes);
        System.out.println("s = " + s);
    }
}
